<template>
	<view class="tongji-box">
		<view class="leaveapply_box">
			<view class="leave_title">
				按班级统计
			</view>
			<view style="display: flex;flex-wrap: wrap"  v-if="classlist">
				<view class="class_box" v-for="item in classlist" @click="tongjilist(item.class_id)">{{item.class_name}}</view>
			</view>
		</view>
		<view class="leaveapply_box">
			<view class="leave_title">
				按月份统计
			</view>
		</view>
		<!-- <view class="class-box">
			<view class="class-box-list" @click="tongjilist(item.class_id)" v-if="classlist"
				v-for="(item,index) in this.classlist" :key="index">
				<view class="banji zhengwen2">
					{{item.class_name}}
				</view>
			</view>

		</view> -->

		<view class="leave-box">
			<uni-collapse v-for="(item,index) in List" :key="index">
				<uni-collapse-item class="biaoticolor" :title="item.mont">
					<view class="leave-content" v-for="(stu,i) in item.stuArr" :key="i" @click="leaveDetail(stu.leave_id)">
						<view class="leave-content-left">
							<view class="leave-content-left-top" v-if="stu">
								<view class="leave-content-name" v-if="stu">{{stu.name}}</view>
								<view class="leave-content-classnumber" v-if="stu">学号：{{stu.sno}}</view>
							</view>
							<view class="leave-content-left-top" v-if="stu">
								<view class="leave-content-classnumber" v-if="stu">班级：{{stu.class_name}}</view>
							</view>
							<view class="leave-content-time">
								<view class="leave-tiem" v-if="stu">请假时间：（总时长{{stu.hours}}小时）</view>
								<view class="leave-date" v-if="stu">{{stu.begintime?stu.begintime.substring(0,16):''}} 至 
																										 {{stu.endtime?stu.endtime.substring(0,16):''}}</view>
							</view>
						</view>
						<view class="leave-content-right">
							<!-- <view class="leave-content-classnumber" v-if="stu">班级：{{stu.class_name}}</view> -->
							<button class="button_status" style="color: #77312A;">{{stu.status}}</button>
						</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>

		<!-- <view class="fenlei-box">
			<uni-collapse v-for="(item,index) in List" :key="index">
				<uni-collapse-item class="biaoticolor" :title="item.mont">
					<view class="neirong" v-for="(stu,i) in item.stuArr" :key="i">
						<view class="neirong-top">
							<view class="xingming zhengwen2">{{stu.name}}</view>
							<view class="xuehao zhengwen2"> 学号：{{stu.sno}}</view>
							<view class="banji zhengwen2">班级：{{stu.class_name}}</view>
						</view>
						<view class="neirong-bottom">
							<view class="neirong-bottom-left">
								<view class="chichang zhengwen2">
									请假时间：（总时长{{stu.hours}}小时）
								</view>
								<view class="shijian zhengwen2">
									{{stu.begintime}} 至 {{stu.endtime}}
								</view>
							</view>
							<view class="neirong-bottom-right">
								<view class="zhuangtai zhengwen2">
									{{stu.status}}
								</view>
							</view>
						</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view> -->
	

	</view>
</template>

<script>
	export default {
		data() {
			return {
				//班级列表
				classlist: [],
				//月份列表
				List: [],

				titlen: '2022年11月',
				time: '40',
				banji: '软件一班'
			}
		},
		mounted() {
			// 请求接口 ↓↓↓
			//查询教师名下班级信息
			let arr = []
			uni.request({
					// url: "/api/appteacher/getclassname",
					url: this.baseUrl+ "/appteacher/getclassname?satoken="+uni.getStorageSync('satoken'),
					headers: {
						// "token": localStorage.getItem("token")
					},
					success: (res) => {
						this.classlist = res.data.result
						console.log(this.classlist)
					}
				}),

				// 请求接口 ↓↓↓
				//教师端查询学生请假月份(统计)
				uni.request({
					// url: "/api/appteacher/getMonthOfTeacher",
					url: this.baseUrl+ "/appteacher/getMonthOfTeacher?satoken="+uni.getStorageSync('satoken'),
					method: "POST",
					headers: {
						// "token": localStorage.getItem("token")
					},
					success: (res) => {
						res.data.result.forEach((v, i) => {
							arr.push(
								new Promise((resolve, reject) => {
									uni.request({
										// url: "/api/appteacher/getLeaveList",
										url: this.baseUrl+ "/appteacher/getLeaveList?satoken="+uni.getStorageSync('satoken'),
										method: "POST",
										headers: {
											// "token": localStorage.getItem("token")
										},
										data: {
											create_time: v.mont
										},
										success: (r) => {
											v.stuArr = r.data.list;
											resolve(v)
										}
									})
								})
							)
						})

						Promise.all(arr).then(res => {
							this.List = res
						})
					}
				})

		},
		methods: {
			
			//点击班级
			tongjilist(banji) {
				uni.navigateTo({
					url: '/pages/tongjilist/tongjilist?banji=' + banji
				});
			},
			// 点击学生信息，查看请假详情
			leaveDetail(id){
				uni.navigateTo({
					url: '/pages/qingjiazhongDetails/qingjiazhongDetails?id='+id
				});
				
			}
		}
	}
</script>

<style lang="scss">
	@import url(@/static/common.css);
	.leaveapply_box{padding: 0;}
	
</style>
